	
	
	import java.util.ArrayList;
	// BankDatabase.java
	// Represents the bank account information database 
	
	public class BankDatabase {
		
	   private Administrator admin;
	   private Customer c1;
	   private Customer c2;
	   private Customer c3;
	   private ArrayList<Customer> customerList;
	
	   // no-argument BankDatabase constructor initializes 
	   // administrator, customers and accounts
	   public BankDatabase()
	   {
		  customerList = new ArrayList<Customer>();
		  admin = new Administrator(1337L,1337);
		  c1 = new Customer (2710912316L, 54321, "Kunde", "Et" );
		  c2 = new Customer (1901882322L, 12345, "Kunde", "To" );
		  c3 = new Customer (2309902343L, 11111, "Kunde", "Tre");
		  
		  customerList.add(c1);
		  customerList.add(c2);
		  customerList.add(c3);
		  customerList.remove(c3);
	  c1.addAccount
	  	(new Account ("Kassekredit", 54321, 2000.0, 2000.0));
	  c1.addAccount
	  	(new Account ("Opsparing", 98765, 40000.0, 40000.0));
	  c2.addAccount
	  	(new Account ("Kassekredit", 22222, 1000.0, 1000.0));
	  c2.addAccount
	  	(new Account ("Opsparing", 33333, 13000.0, 13000.0));
   } // end no-argument BankDatabase constructor
  
   //returns administrator if userNumber is correct
   public Administrator getAdministrator(long userNumber)
   {
	   if (admin.getUsernumber() == userNumber)
		   return admin;
	   else 
		   return null;
   }//end method getAdministrator
   
   // retrieve Customer object containing specified cpr number
   public Customer getCustomer( long userCpr )
   {
      // loop through customers searching for matching cpr number
      for ( Customer currentCustomer : customerList )
      {
         // return current customer if match found
         if ( currentCustomer.getCpr() == userCpr )
            return currentCustomer;
      } // end for

      return null; // if no matching customers was found, return null
   } // end method getCustomer

   // determine whether user-specified CPR number and PIN match
   // those of an customer in the database
   public boolean authenticateUser( long userCpr, int userPIN )
   {
      // attempt to retrieve the user with the cpr number
	   Customer user = getCustomer( userCpr );

      // if customer exists, return result of Customer method validatePIN
	   if ( user != null )
	         return user.validatePIN( userPIN );
	      else
	      {
	    	  Administrator admin = getAdministrator(userCpr); 
	    	// if administrator exists, return result of Administrator method validatePass
	    	  if (admin != null)
	    		  return admin.validatePass(userPIN); 
	    	  else
	    		  return false; // account number not found, so return false
	      }
	   } // end method authenticateUser

   // return available balance of Account with specified account number
   public double getAvailableBalance(long userCpr, int userAccountNumber )
   {
      return getCustomer(userCpr).getAccount( userAccountNumber ).getAvailableBalance();
   } // end method getAvailableBalance

   // return total balance of Account with specified account number
   public double getTotalBalance( long userCpr, int userAccountNumber )
   {
      return getCustomer(userCpr).getAccount( userAccountNumber ).getTotalBalance();
   } // end method getTotalBalance

   // credit an amount to Account with specified account number
   public void credit(long userCpr, int userAccountNumber, double amount )
   {
      getCustomer(userCpr).getAccount( userAccountNumber ).credit( amount );
   } // end method credit

   // debit an amount from Account with specified account number
   public void debit(long userCpr, int userAccountNumber, double amount )
   {
      getCustomer(userCpr).getAccount( userAccountNumber ).debit( amount );
   } // end method debit
   
   //adds an amount to account with specified account number
   public void transfer(long userCpr, int userAccountNumber, double amount)
   {
	   getCustomer(userCpr).getAccount( userAccountNumber ).transfer(amount);
   } //end method transfer
   
   // method to add new customer
   public void addNewCustomer(long userCpr, int userPin, 
		   					String userFirstName, String userLastName)
   {
	  customerList.add
	  	(new Customer (userCpr, userPin, userFirstName, userLastName ));
   } // end method addNewCustomer
   
   //method to delete customer
   public void deleteCustomer(long userCpr)
   {
	   customerList.remove(getCustomer(userCpr));
   } // end method deleteCustomer
   
   //method to add new account
   public void addNewAccount(long userCpr, String userAccountName, int userAccountNumber, double theAvailableBalance, double theTotalBalance )
   {
	   getCustomer(userCpr).addAccount(new Account(userAccountName, userAccountNumber, theAvailableBalance, theTotalBalance));
   }//end method addNewAccount
 
   //method to delete existing account
   public void deleteAccount(long userCpr, int userAccountNumber)
   {
	   getCustomer(userCpr).deleteAccount(getCustomer(userCpr).getAccount(userAccountNumber));
   }
   
   // returns the customerList
   public ArrayList<Customer> getList()
   {
	   return customerList;
   }//end method getList
   
} // end class BankDatabase
